var util = {}
util.url1='http://localhost:8081';
//util.url='http://10.38.240.30:18678';
util.url='http://10.39.33.76:8081';

util.tablename="gastable";
//util.url='http://10.4.106.30:18855/';
util.ajax = function(param,url,sucfun,failfun) { //跨域使用请求
    var layindex = layui.layer.load(1);
	$.ajax( {  
	    url:url,// actiteston url
	    type:"post",
	    cache:false,

        data: JSON.stringify(param),
        contentType: "application/json;charset=utf-8",
	    success:function(data) {
            layui.layer.close(layindex);
	    	sucfun(data);
	     },
	     error : function() {
             layui.layer.close(layindex);
	    	 failfun();
	     }  
	});

}
util.ajaxget = function(url,sucfun,failfun) {//跨域使用请求
    var layindex = layui.layer.load(1);
    $.ajax( {
        url:url,// action url
        type:"get",
        cache:false,
        contentType: "application/json;charset=utf-8",
        success:function(data) {
            layui.layer.close(layindex);
            sucfun(data);
        },
        error : function() {
            layui.layer.close(layindex);
            failfun();
        }
    });

}
util.ajaxget1 = function(url,sucfun,failfun) {//跨域使用请求 无加载
    $.ajax( {
        url:url,// action url
        type:"get",
        cache:false,
        contentType: "application/json;charset=utf-8",
        success:function(data) {
            sucfun(data);
        },
        error : function() {
            failfun();
        }
    });

}
util.ajaxdelete = function(url,sucfun,failfun) {//跨域使用请求
    var layindex = layui.layer.load(1);
    $.ajax( {
        url:url,// action url
        type:"delete",
        cache:false,
        contentType: "application/json;charset=utf-8",
        success:function(data) {
            layui.layer.close(layindex);
            sucfun(data);
        },
        error : function() {
            layui.layer.close(layindex);
            failfun();
        }
    });

}
//局部刷新页面的form提交
util.ajaxFrom = function(formId,url,sucfun,failfun) {
	$.ajax({
	    url:url,// action url
	    data:$("#"+formId).serialize(),    
	    type:"post",  
	    cache:false,  
	    //dataType:"json",
	    success:function(data) {
	    	sucfun(data);
	    	//$("#loading").hide();
	     },  
	     error : function() {  
	    	 failfun();
	    	// $("#loading").hide();
	     }  
	});
}

util.ajax1 = function(param,url,sucfun,failfun) {
	//$("#loading").show();
	//document.getElementById('loading').style.display='block';
	$.ajax( {  
	    url:url,// action url
	    data:param,  
	    type:"post",
        contentType: "application/x-www-form-urlencoded",
        dataType:"json",
        cache:false,
	    success:function(data) {
	    	if(typeof data!="string"){
	    		var da=eval(data);
				if(da.hasOwnProperty("islogin")){
					$("#loading").hide();
					window.location.reload(true);
					return;
				}
	    	}
	    	sucfun(data);
	    	//$("#loading").hide();
	     },  
	     error : function() {  
	    	 failfun();
	    	 //$("#loading").hide();
	     }  
	});

}

//拼装table数据
function getTableData(tablename){
	var _table=document.getElementById(tablename);
	var rows=_table.rows;
	var jsonStr="[";
	for(var i=1;i<rows.length;i++){
		var columns=rows[i].cells;
		var ids=rows[0].cells;
		if(i==1){
			jsonStr+="{";
		}else{
			jsonStr+=",{";
		}
		
		for(var j=0;j<columns.length;j++){
			var txt="";
			if($(columns[j]).children('INPUT').length>0){
				txt=$(columns[j]).children('input').eq(0).val();
			}else if($(columns[j]).children('SELECT').length>0){
				txt=$(columns[j]).children('select').eq(0).find("option:selected").val();
			}else if($(columns[j]).children('BUTTON').length>0){
				txt=$(columns[j]).children('button').text();
			}else if($(columns[j]).children('a').length>0){
				
			}else{
				txt=columns[j].innerHTML;
			}
			
			if(j==0){
				jsonStr+="\""+ids[j].id+"\""+":\""+txt+"\"";
			}else{
				
				jsonStr+=",\""+ids[j].id+"\""+":\""+txt+"\"";
			}
		}
		jsonStr+="}";
	}
	jsonStr+="]";
	return jsonStr;
}

//拼装table数据
function getTableContent(tablename){
    var _table=document.getElementById(tablename);
    var rows=_table.rows;
    var jsonStr="[";
    for(var i=1;i<rows.length;i++){
        var columns=rows[i].cells;
        var ids=rows[0].cells;
        if(i==1){
            jsonStr+="{";
        }else{
            jsonStr+=",{";
        }
        for(var j=0;j<columns.length;j++){
            var txt="";
            if($(columns[j]).children('INPUT').length>0){
                txt=$(columns[j]).children('input').eq(0).val();
            }else if($(columns[j]).children('SELECT').length>0){
                txt=$(columns[j]).children('select').eq(0).find("option:selected").val();
            }else if($(columns[j]).children('BUTTON').length>0){
                txt=$(columns[j]).children('button').text();
            }else if($(columns[j]).children('a').length>0){

            }else{
                txt=columns[j].innerHTML;
            }

            if(j==0){
                jsonStr+="\""+ids[j].getAttribute('fieldname')+"\""+":\""+txt+"\"";
            }else{

                jsonStr+=",\""+ids[j].getAttribute('fieldname')+"\""+":\""+txt+"\"";
            }
        }
        jsonStr+="}";
    }
    jsonStr+="]";
    return jsonStr;
}
$.fn.serializeObject = function()
{
   var o = {};
   var a = this.serializeArray();
   $.each(a, function() {
       if (o[this.name]) {
           if (!o[this.name].push) {
               o[this.name] = [o[this.name]];
           }
           o[this.name].push(this.value || '');
       } else {
           o[this.name] = this.value || '';
       }
   });
   return o;
};
var mytaskdata=[];
var request = {
    QueryString : function(val) {
        var uri = window.location.search;
        var re = new RegExp("" +val+ "\=([^\&\?]*)", "ig");
        return ((uri.match(re))?(uri.match(re)[0].substr(val.length+1)):null);
    },
    QueryStrings : function() {
        var uri = window.location.search;
        var re = /\w*\=([^\&\?]*)/ig;
        var retval=[];
        while ((arr = re.exec(uri)) != null)
            retval.push(arr[0]);
        return retval;
    },
    setQuery : function(val1, val2) {
        var a = this.QueryStrings();
        var retval = "";
        var seted = false;
        var re = new RegExp("^" +val1+ "\=([^\&\?]*)$", "ig");
        for(var i=0; i<a.length; i++) {
            if (re.test(a[i])) {
                seted = true;
                a[i] = val1 +"="+ val2;
            }
        }
        retval = a.join("&");
        return "?" +retval+ (seted ? "" : (retval ? "&" : "") +val1+ "=" +val2);
    }
}


//-->